// 第六步，运行服务端

#include "TcpServer.hpp"
#include "Protocol.hpp"
#include "ServerCal.hpp"
#include "Daemon.hpp"
#include <unistd.h>

void Usage(const std::string& proc)
{
    std::cout << "\nUsage: " << proc << " port[1024+]\n" << std::endl;
}

// ./servercal 8080
int main(int argc, char* argv[])
{
    if(argc != 2)
    {
        Usage(argv[0]);
        exit(0);
    }
    uint16_t port = std::stoi(argv[1]);

    ServerCal cal;
    TcpServer* tsvp = new TcpServer(port, std::bind(&ServerCal::Calculator, &cal, std::placeholders::_1));  // ?
    tsvp->InitServer();
    Daemon();
    tsvp->Start();

    return 0;
}
